package com.ratp.basedonnees;

import android.database.Cursor;

import com.ratp.bean.Expertise;
import com.ratp.bean.Marque;
import com.ratp.bean.Type;

public class UtilsBDD {

	/**
	 * Transforme le cursor en un objet expertise
	 * @param cursor
	 * @return
	 */
	public static Expertise recupererObjetExpertiseDepuisCursor(Cursor cursor) {
		Expertise expertise = null;
		// GetCont c'est pour dire s'il y'a au mons une lignes
		if (cursor != null && cursor.getCount() > 0) {
			expertise = new Expertise();
			// Le cursor retourne un objet de type String donc il faut le convertir en int
			// On met dans l'objet expertise les informations de curseur
			expertise.setId(cursor.getInt(BDDinfo.TABLE_EXPERTISES.COLONNES.ID.INDEX));
			expertise.setEntreprise(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.ENTREPISE.INDEX));
			expertise.setBanDeFrinage(("O".equals(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.BAN_FREINAGE.INDEX))) ? true : false);
			expertise.setBanDFreinageHuimide(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.BAN_FREINAGE_HUMIDE.INDEX)));
			expertise.setBanDeFreinageSec(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.BAN_FREINAGE_SEC.INDEX)));
			expertise.setBanDeFreinageValur(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.BAN_FREINAGE_VALEUR.INDEX)));
			expertise.setBoiteVitessEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.BOITE_VITESSE_E.INDEX));
			expertise.setBoiteVitesseNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.BOITE_VITESSE_EP.INDEX));
			expertise.setCarrosExtEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.CARROS_EXT_E.INDEX));
			expertise.setCarrosExtNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.CARROS_EXT_EP.INDEX));
			expertise.setCircuitElecMoteurEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.CIRCUIT_ELECRIQUE_MOTEUR_E.INDEX));
			expertise.setCircuitElecMoteurNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.CIRCUIT_ELECRIQUE_MOTEUR_EP.INDEX));
			expertise.setConformiteMontage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.CONFORMITE_MONTAGE.INDEX));
			expertise.setDateControl(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DATE_CONTROLE.INDEX));
			expertise.setDateMisEnService(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DATE_MISE_EN_SERVICE.INDEX));
			expertise.setDecelometre(("O".equals(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DECELOMETRE.INDEX))) ? true : false);
			expertise.setDecelometreSec(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DECELOMETRE_SEC.INDEX)));
			expertise.setDecelometreHuimide(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DECELOMETRE_HUMIDE.INDEX)));
			expertise.setDecelometreValeur(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DECELOMETRE_VALEUR.INDEX)));
			expertise.setDirctionEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DIRECTION_E.INDEX));
			expertise.setDirctionNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DIRECTION_EP.INDEX));
			expertise.setDiversElectEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DIVERS_ELECTRIQUE_E.INDEX));
			expertise.setDiversElectNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.DIVERS_ELECTRIQUE_EP.INDEX));
			expertise.setFreinsEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.FREINS_E.INDEX));
			expertise.setFreinsNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.FREINS_EP.INDEX));
			expertise.setImmatricul(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.IMMATRICULATION.INDEX));
			expertise.setVisiteControl(("O".equals(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.VISITE_CONTROLE.INDEX))) ? true : false);
			expertise.setVisiteControloCom(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.VISITE_CONTROLE_COMMENTAIRE.INDEX));
			expertise.setVisiteDrire("O".equals(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.VISITE_DRIRE.INDEX))? true : false);
			expertise.setVisiteDrireCom(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.VISITE_DRIRE_COMMENTAIRE.INDEX));
			expertise.setKmJourCont(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.KM_JOUR_CONT.INDEX));
			
			Marque m = new Marque();
			m.setId(cursor.getInt(BDDinfo.TABLE_EXPERTISES.COLONNES.MARQUE.INDEX));
			m.setMarque("");
			
			expertise.setMarque( m );
			
			expertise.setMoteurEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.MOTEUR_E.INDEX));
			expertise.setMoteurNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.MOTEUR_EP.INDEX));
			expertise.setNoteCarros(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.NOTE_CARROSSERIE.INDEX)));
			expertise.setNoteElec(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.NOTE_ELECTRIQUE.INDEX)));
			expertise.setNoteGeneral(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.NOTE_GENERALE.INDEX)));
			expertise.setNoteMecanique(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.NOTE_MECANIQUE.INDEX)));
			expertise.setNumParc(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.NUM_PARC.INDEX));
			expertise.setPareBriseEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.PAREBRISE_E.INDEX));
			expertise.setPareBriseNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.PAREBRISE_EP.INDEX));
			expertise.setPneuma1(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.PNEUMATIQUE_1.INDEX)));
			expertise.setPneuma3(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.PNEUMATIQUE_3.INDEX)));
			expertise.setPneuma2(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.PNEUMATIQUE_2.INDEX)));
			expertise.setPneuma4(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.PNEUMATIQUE_4.INDEX)));
			expertise.setPneuma5(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.PNEUMATIQUE_5.INDEX)));
			expertise.setPneuma6(Integer.parseInt(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.PNEUMATIQUE_6.INDEX)));
			expertise.setPosteConduiteEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.POSTE_CONDUITE_E.INDEX));
			expertise.setPosteConduiteNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.POSTE_CONDUITE_EP.INDEX));
			expertise.setRmapePMREngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.RAMPE_PMR_E.INDEX));
			expertise.setRmapePMRNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.RAMPE_PMR_EP.INDEX));
			expertise.setRemarqueParticulieres(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.REMARQUE.INDEX));
			expertise.setSellerieEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.SELLERIE_E.INDEX));
			expertise.setSellerieNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.SELLERIE_EP.INDEX));
			expertise.setSignalisationExtEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.SIGNE_EXTRIEUR_E.INDEX));
			expertise.setSignalisationExtNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.SIGNE_EXTRIEUR_EP.INDEX));
			expertise.setSuspensionEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.SUSPENSION_E.INDEX));
			expertise.setSuspensionNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.SUSPENSION_EP.INDEX));
			expertise.setTransmissionEngage(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.TRANSMISSION_E.INDEX));
			expertise.setTransmissionNengagePas(cursor.getString(BDDinfo.TABLE_EXPERTISES.COLONNES.TRANSMISSION_EP.INDEX));
			
			Type t = new Type();
			t.setType("");
			t.setId(cursor.getInt(BDDinfo.TABLE_EXPERTISES.COLONNES.TYPE.INDEX));
			
			expertise.setType(t);
		}
		return expertise;
	}

	public static Marque recupererObjetMarqueDepuisCursor(Cursor c) {
		Marque m = null;
		if (c != null && c.getCount() > 0) {
			m = new Marque();
			m.setId(c.getInt(BDDinfo.TABLE_MARQUES.COLONNES.ID.INDEX));
			m.setValue(c.getString(BDDinfo.TABLE_MARQUES.COLONNES.MARQUE.INDEX));
		}
		return m;
	}
	public static Type recupererObjetTypeDepuisCursor(Cursor c) {
		Type t = null;
		if (c != null && c.getCount() > 0) {
			t = new Type();
			t.setId(c.getInt(BDDinfo.TABLE_MARQUES.COLONNES.ID.INDEX));
			t.setType(c.getString(BDDinfo.TABLE_MARQUES.COLONNES.MARQUE.INDEX));
		}
		return t;
	}

}
